//
// Prob.cpp for math 202 in /home/druart_p/Work/math/my-math-epi/202
//
// Made by pierrick druart
// Login   <druart_p@epitech.net>
//
// Started on  Tue Feb 28 09:21:14 2012 pierrick druart
// Last update Mon Mar 12 10:54:43 2012 pierrick druart
//

#include <sstream>
#include <iostream>
#include <iomanip>

#include "Prob.hpp"
#include "Calc.hh"

Prob::Prob(const std::string & str)
{
  std::istringstream	iss(str);

  iss >> this->val_;
  if (this->val_ <= 5 && this->val_ > 0)
    {
  this->func_[1] = &Prob::option1;
  this->func_[2] = &Prob::option2;
  this->func_[3] = &Prob::option3;
  this->func_[4] = &Prob::option4;
  this->func_[5] = &Prob::option5;
    }
  else
    throw my_exception_arg(str);
  exec();
}

Prob::~Prob()
{
  this->func_.clear();
}

void	Prob::exec()
{
  (this->*func_[this->val_])();
}

void	Prob::option1()
{
  Calc	calc;
  std::cout << "\t\tX=1\tX=2\tX=3\tX=4\tX=5\tLoi de Y" << std::endl;
  std::cout << " Y = 1 \t\t" << std::setprecision(3) << calc.conj(1, 1) << "\t" << calc.conj(2, 1) << "\t" <<  calc.conj(3, 1) << "\t" << calc.conj(4, 1) << "\t" << calc.conj(5, 1) << "\t" << calc.marg_y(1) << std::endl;
  std::cout << " Y = 2 \t\t" << std::setprecision(2) << calc.conj(1, 2) << "\t" << calc.conj(2, 2) << "\t" <<  calc.conj(3, 2) << "\t" << calc.conj(4, 2) << "\t" << calc.conj(5, 2) << "\t" << calc.marg_y(2) << std::endl;
  std::cout << " Y = 3 \t\t" << std::setprecision(2) << calc.conj(1, 3) << "\t" << calc.conj(2, 3) << "\t" <<  calc.conj(3, 3) << "\t" << calc.conj(4, 3) << "\t" << calc.conj(5, 3) << "\t" << calc.marg_y(3) << std::endl;
  std::cout << " Y = 4 \t\t" << std::setprecision(2) << calc.conj(1, 4) << "\t" << calc.conj(2, 4) << "\t" <<  calc.conj(3, 4) << "\t" << calc.conj(4, 4) << "\t" << calc.conj(5, 4) << "\t" << calc.marg_y(4) << std::endl;
  std::cout << " Y = 5 \t\t" << std::setprecision(2) << calc.conj(1, 5) << "\t" << calc.conj(2, 5) << "\t" <<  calc.conj(3, 5) << "\t" << calc.conj(4, 5) << "\t" << std::setprecision(1) << calc.conj(5, 5) << "\t" << calc.marg_y(5) << std::endl;
  std::cout << " Loi de X \t" << std::setprecision(3) << calc.marg_x(1) <<  "\t" <<  calc.marg_x(2) <<  "\t" <<  calc.marg_x(3) << "\t" << std::setprecision(2) << calc.marg_x(4) << "\t" << calc.marg_x(5) << "\t1"<< std::endl;
}

void	Prob::option2()
{
  Calc	calc;

  std::cout << "Esperence de X = " << std::setprecision(4) << calc.E_x() << std::endl;
  std::cout << "Variance de X = " << std::setprecision(4) << calc.Var_x() << std::endl;
  std::cout << "Esperence de Y = " << std::setprecision(4) << calc.E_y() << std::endl;
  std::cout << "Variance de Y = " << std::setprecision(4) << calc.Var_y() << std::endl;
}

void	Prob::option3()
{
  Calc	calc;

  std::cout << "\tZ = 2\tZ = 3\tZ = 4\tZ = 5\tZ = 6\tZ = 7\tZ = 8\tZ = 9\tZ = 10\tTotal" << std::endl;
  std::cout << "P(Z=z)\t" << std::setprecision(3) << calc.prob(2) << "\t" << calc.prob(3) << "\t" << calc.prob(4) << "\t" << calc.prob(5) << "\t" << calc.prob(6) << "\t" <<  calc.prob(7) << "\t" << std::setprecision(2) << calc.prob(8) << "\t" << calc.prob(9) << std::setprecision(1) << "\t" << calc.prob(10) << "\t 1" << std::endl;

}

void	Prob::option4()
{
  Calc	calc;

  std::cout << "z\t2\t3\t4\t5\t6\t7\t8\t9\t10" << std::endl;
  std::cout << "F(z)\t" << std::setprecision(3) << calc.rep(2) << "\t" << calc.rep(3) << "\t" << calc.rep(4) << "\t" << calc.rep(5) << "\t" << calc.rep(6) << "\t" <<  calc.rep(7) << "\t" << calc.rep(8) << "\t" << calc.rep(9) << "\t" << calc.rep(10) << std::endl;

}

void	Prob::option5()
{
  Calc	calc;

  std::cout << "Esperence de Z = " << std::setprecision(4) << calc.E_z() << std::endl;
  std::cout << "Variance de Z = " << std::setprecision(4) <<  calc.Var_z() << std::endl;
}
